﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Contracts;

namespace Radar {

    public class Repository : IRepository {

        private static IRepository _current;
        public readonly Object _modelLock = new Object();
        private List<IEvent> _model;
        private int _currId;

        private Repository() {
            _model = new List<IEvent>();
        }

        public static IRepository GetInstance() {
            if (_current == null) {
                _current = new Repository();
            }
            return _current;
        }

        public void AddEvent(IEvent evt) {
            lock (_modelLock) {
                evt.SetId(_currId++);
                _model.Add(evt);
            }
        }

        public List<IEvent> PeekEvents() {
            List<IEvent> ret = new List<IEvent>(_model);
            return ret;
        }

        public List<IEvent> ReadEvents() {
            List<IEvent> ret = new List<IEvent>(_model);
            _model.Clear();
            return ret;
        }
    }
}
